package org.lc.stk.web.dto.question;

import java.util.ArrayList;
import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

@Schema(description = "选择题数据传输对象")
public class ChoiceQuestionDTO extends QuestionResponseDTO {
    
    @Schema(description = "题干富文本内容")
    @NotBlank(message = "题干不能为空")
    private String stemContent;
    
    @Schema(description = "选项列表")
    @NotNull(message = "选项列表不能为空")
    @Size(min = 2, message = "至少需要两个选项")
    private List<ChoiceOptionDTO> options = new ArrayList<>();
    
    @Schema(description = "是否为多选题")
    private boolean multiple;
    
    @Schema(description = "正确答案的选项序号列表")
    @NotNull(message = "正确答案不能为空")
    @Size(min = 1, message = "至少需要一个正确答案")
    private List<Integer> correctOptionIndexes = new ArrayList<>();

    // 添加无参构造函数
    public ChoiceQuestionDTO() {
        super();
    }

    @Schema(description = "选择题选项")
    public static class ChoiceOptionDTO {
        @Schema(description = "选项富文本内容")
        @NotBlank(message = "选项内容不能为空")
        private String content;
        
        @Schema(description = "选项序号，从1开始")
        @NotNull(message = "选项序号不能为空")
        private Integer index;

        public ChoiceOptionDTO() {
        }

        public ChoiceOptionDTO(String content, Integer index) {
            this.content = content;
            this.index = index;
        }

        // Getters and Setters
        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public Integer getIndex() {
            return index;
        }

        public void setIndex(Integer index) {
            this.index = index;
        }
    }

    // Getters and Setters
    public String getStemContent() {
        return stemContent;
    }

    public void setStemContent(String stemContent) {
        this.stemContent = stemContent;
    }

    public List<ChoiceOptionDTO> getOptions() {
        return options;
    }

    public void setOptions(List<ChoiceOptionDTO> options) {
        this.options = options;
    }

    public void addOption(String content, Integer index) {
        this.options.add(new ChoiceOptionDTO(content, index));
    }

    public boolean isMultiple() {
        return multiple;
    }

    public void setMultiple(boolean multiple) {
        this.multiple = multiple;
    }

    public List<Integer> getCorrectOptionIndexes() {
        return correctOptionIndexes;
    }

    public void setCorrectOptionIndexes(List<Integer> correctOptionIndexes) {
        this.correctOptionIndexes = correctOptionIndexes;
    }

    public void addCorrectOptionIndex(Integer index) {
        this.correctOptionIndexes.add(index);
    }
}